//
//  UIUTils.m
//  SchoolCircle
//
//  Created by 战立军 on 16/5/28.
//  Copyright © 2016年 战立军. All rights reserved.
//

#import "UIUTils.h"
#import "TPKeyboardAvoidingScrollView.h"

@implementation UIUTils
#pragma mark 公用的
/**
 *  屏幕的宽度
 *
 *  @return
 */
+ (CGFloat)getWindowWidth
{
    UIWindow *mainWindow = [UIApplication sharedApplication].windows[0];
    return mainWindow.frame.size.width;
}
/**
 *  屏幕的高度
 *
 *  @return <#return value description#>
 */
+ (CGFloat)getWindowHeight
{
    UIWindow *mainWindow = [UIApplication sharedApplication].windows[0];
    return mainWindow.frame.size.height;
}

/**
 *  根据色值返回颜色
 *
 *  @param hexString 色值
 *
 *  @return 颜色
 */
+ (UIColor *)colorFromHexCode:(NSString *)hexString {
    NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
    if([cleanString length] == 3) {
        cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
                       [cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
                       [cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
                       [cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
    }
    if([cleanString length] == 6) {
        cleanString = [cleanString stringByAppendingString:@"ff"];
    }
    
    unsigned int baseValue;
    [[NSScanner scannerWithString:cleanString] scanHexInt:&baseValue];
    
    float red = ((baseValue >> 24) & 0xFF)/255.0f;
    float green = ((baseValue >> 16) & 0xFF)/255.0f;
    float blue = ((baseValue >> 8) & 0xFF)/255.0f;
    float alpha = ((baseValue >> 0) & 0xFF)/255.0f;
    
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}


#pragma mark 本程序独有的

+ (TPKeyboardAvoidingScrollView *)addTPScrollView
{
    TPKeyboardAvoidingScrollView *scrollview = [[TPKeyboardAvoidingScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIUTils getWindowWidth], [UIUTils getWindowHeight])];
    scrollview.backgroundColor = [UIColor clearColor];
    // 设置内容大小
    scrollview
    .contentSize = CGSizeMake([UIUTils getWindowWidth], [UIUTils getWindowHeight]);
    // 提示用户,Indicators flash
    [scrollview flashScrollIndicators];

    return scrollview;
    
}

@end
